package com.example.sjm.activity_bysjm;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;

import java.util.List;

import cn.bmob.v3.Bmob;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;

public class Activity_content extends AppCompatActivity{
    private ImageView photo;
    private TextView name;
    private TextView time;
    private TextView location;
    private TextView content;
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_content);
        Bmob.initialize(this, "dfb070b70fb6d635bbecf1309049e49f");
        photo=findViewById(R.id.img);
        name=findViewById(R.id.name1);
        time=findViewById(R.id.time2);
        location=findViewById(R.id.location2);
        content=findViewById(R.id.content2);
        query();
    }
    public void query( ){
        BmobQuery<com.example.sjm.activity_bysjm.Activity> bmobQuery=new BmobQuery<>();

        String id1 = getIntent().getStringExtra("id");
        System.out.println("id1"+id1);
        Double test_id= Double.valueOf(id1);
        System.out.println("test2"+test_id.intValue());
        int id=test_id.intValue();
     //string 类型的2.0不能直接转换为整型，需要转换为double类型再转换为整型，否则会报格式错误
        bmobQuery.addWhereEqualTo("activity_id",id);

        bmobQuery.findObjects(new FindListener<com.example.sjm.activity_bysjm.Activity >() {
            @Override
            public void done(List<com.example.sjm.activity_bysjm.Activity > list, BmobException e) {
                if(e==null){
                    for(com.example.sjm.activity_bysjm.Activity listViewModel : list){
                        name.setText(listViewModel.getActivity_name());
                        System.out.println(listViewModel.getActivity_location()+"aaaaaaaaa");
                        location.setText(listViewModel.getActivity_location());
                        content.setText(listViewModel.getActivity_content());
                        time.setText(listViewModel.getActivity_time());
                        System.out.println("bmob"+listViewModel.getActivity_photo().getUrl()+"  "+listViewModel.getActivity_name()+" "+listViewModel.getActivity_location());
                        Glide.with(Activity_content.this).load(listViewModel.getActivity_photo().getUrl()).into(photo);
                    }
                }
            }
        });

    }

}
